package com.css.bjdt_report.report.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.css.bjdt_report.report.entity.RptGroup;
import com.css.bjdt_report.report.service.ReportGroupManageService;

@Controller
@RequestMapping(value = "/reportManageController")
public class ReportGroupManageController {

	@Autowired
	private ReportGroupManageService reportGroupManageService;

	@RequestMapping(value = "/preCreateReportGroup/{annualId}", method = RequestMethod.GET)
	public String preCreateReportGroup(@PathVariable String annualId, Model model) {
		model.addAttribute("annualId", annualId);
		return "/report-manage/report-manage-group-input";
	}

	//保存套标信息
	@RequestMapping(value = "/saveReportGroup", method = RequestMethod.POST)
	public String saveReportGroup(RptGroup rptGroup, @RequestParam(value = "annualId") String annualId, Model model) {
		rptGroup.setAnnualId(annualId);
		reportGroupManageService.insertRptGroup(rptGroup);
		model.addAttribute("annualId", annualId);
		model.addAttribute("message", "操作成功");
		return "/report-manage/report-manage-group-input";
	}

	//修改套表预处理
	@RequestMapping(value = "/preUpdate/{groupId}/{annualId}", method = RequestMethod.GET)
	public String preUpdate(@PathVariable String groupId, @PathVariable String annualId, Model model) {
		model.addAttribute(reportGroupManageService.queryByID(groupId));
		model.addAttribute("annualId", annualId);
		return "/report-manage/report-manage-group-input";
	}

	//修改报表模板
	@RequestMapping("/updateGroup")
	public String updateAnnual(RptGroup rptGroup, @RequestParam(value = "annualId") String annualId, Model model) {
		reportGroupManageService.update(rptGroup);
		model.addAttribute("annualId", annualId);
		model.addAttribute("message", "操作成功");
		return "/report-manage/report-manage-group-input";
	}

	//删除一个套表
	@ResponseBody
	@RequestMapping(value = "/deleteReportGroup/{groupId}/{annualId}")
	public String deleteAnnual(@PathVariable String groupId, @PathVariable String annualId) {
		reportGroupManageService.deleteGroup(groupId, annualId);
		return annualId;
	}

	//报表模板明细
	@RequestMapping(value = "/detail/{groupId}", method = RequestMethod.GET)
	public ModelAndView detail(@PathVariable String groupId, Model model) {
		/*model.addAttribute(reportGroupManageService.queryByID(groupId));
		
		return "/report-manage/report-manage-group-detail";*/

		ModelAndView modelAndView = new ModelAndView("/report-manage/report-manage-group-detail");
		RptGroup rptGroup = reportGroupManageService.queryByID(groupId);
		modelAndView.addObject("rptGroup", rptGroup);
		return modelAndView;
	}
}
